//
//  PPHomeViewController.m
//  pickpic
//
//  Created by Jinxiao on 8/28/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "PPHomeViewController.h"
#import "PPContactsSegmentedViewController.h"
#import "PPSettingViewController.h"
#import "PPMyFavouritesViewController.h"
#import "PPFoundViewController.h"
#import "PPMiaoTimelineViewController.h"
#import "PPFriendsTimelineViewController.h"
#import "PPAlbumPreviewViewController.h"
#import "PPAlbumContentViewController.h"
#import "PPWebGrabViewController.h"
#import "PPProfileViewController.h"
#import "PPAssetsPickerViewController.h"
#import "PPAlbumPictureInsertionViewController.h"
#import "PPCameraViewController.h"
#import "PPAssetsPickerViewController.h"

#import "PPHomeDashboardView.h"
#import "PPHomeDashboardViewBadgeCell.h"

#import "PPHomeAlbumListView.h"
#import "PPHomeAlbumSearchView.h"

#import "PPHomeDotView.h"

#import "PPAlbumShareActionView.h"
#import "PPAlbumShareView.h"

#import "PPHomePickerView.h"

#import "PPAlbumManager.h"
#import "PPSocializationManager.h"
#import "PPUnreadMessageManager.h"

#import "PPAlbumModel.h"
#import "PPShareTemplateController.h"
#import "PPHomeAlbumModel.h"
#import "PPCommonPicturesUploaderManager.h"
#import "PPUploadPicture.h"
#import "PPSheetView.h"
#import "PPSettingViewController.h"
#define kFistToast @"fistToastAlbum"
#import "PPHomeAlumAddImageController.h"

#import "PPHomeEbookModel.h"
#import "PPTemplateModel.h"
#import "PPEbookAlbum.h"
#import "PPAlbumEditContentViewController.h"
#import "PPCoverAlertView.h"
//#define PPNavBarLineColor (COLORA(218, 218, 218))
#define PPNavBarLineColor (COLORA(200, 200, 200))
@interface PPHomeViewController () <PPHomeDashboardViewDelegate, PPHomeAlbumListViewDelegate, PPAssetsPickerViewControllerDelegate, PPHomeAlbumSearchViewDelegate, PPCameraViewControllerDelegate,PPSheetViewDelegate,TZImagePickerControllerDelegate>
@property (readwrite, nonatomic, strong) PPHomeDashboardView *dashboardView;
@property (readwrite, nonatomic, strong) PPHomeAlbumListView *listView;
@property (readwrite, nonatomic, strong) PPHomeAlbumSearchView *searchView;

@property (readwrite, nonatomic, strong) UIView *topBar;
@property (readwrite, nonatomic, strong) UIView *bottomBar;
@property (readwrite, nonatomic, strong) UIButton *createButton;
@property (readwrite, nonatomic, strong) UIImageView *whiteLogoView;
@property (readwrite, nonatomic, strong) UIImageView *blackLogoView;
@property (readwrite, nonatomic, strong) UIButton *searchButton;
@property (readwrite, nonatomic, strong) UIButton *cameraButton;
@property (readwrite, nonatomic, strong) PPHomeDotView *dotView;

@property (readwrite, nonatomic, assign) PPHomeViewState state;
@property (nonatomic, assign) BOOL isSearchShown;
@property (nonatomic,strong) UIImageView *topBarLine;
//@property (nonatomic,strong) UIButton *addBtn;
//@property (nonatomic,strong) PPHomePickerView *pickerView;
//@property (nonatomic,strong) DGPopoverView *poverView;
@property (nonatomic,strong) PPSheetView *sheetView;

//@property (nonatomic,strong) PPShareTemplateController *shareViewController;

@property (nonatomic,strong) UIView *coverView;

@property (nonatomic,strong) PPCoverAlertView *coverAlert;
@property (nonatomic,strong) UIButton *coverEbookBtn;
@end

@implementation PPHomeViewController
//- (PPShareTemplateController *)shareViewController{
//
//    if (!_shareViewController) {
//        _shareViewController = [[PPShareTemplateController alloc] init];
//    }
//    return _shareViewController;
//}
- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
- (UIButton *)cameraButton{

    if (!_cameraButton) {
        _cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _cameraButton.contentEdgeInsets = UIEdgeInsetsMake(6, 6,6, 6);
        [_cameraButton setImage:[UIImage imageNamed:@"icon-add-black"/*@"icon-nav-camera"*/] forState:UIControlStateNormal];
//        _cameraButton.backgroundColor = BLUE;
        [_cameraButton sizeToFit];
//         _cameraButton.backgroundColor = RED;
        [_cameraButton addTarget:self action:@selector(createButtonDidPressed:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cameraButton;
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)judgeVersion{
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"myDateKey"]) {
        NSDate *myDate = (NSDate *)[[NSUserDefaults standardUserDefaults] objectForKey:@"myDateKey"];
        if ([myDate getDifferenceByDate]>=2) {
            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"waiveUpdate"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    }
    
    
    [UIApplication isUpdateVersion:^(NSString *versionTitle,NSString *meg) {
        if (versionTitle.length > 0 && ![[[NSUserDefaults standardUserDefaults] objectForKey:@"waiveUpdate"] boolValue]) {
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:versionTitle message:meg preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"放弃" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"waiveUpdate"];
                [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"myDateKey"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                
            }];
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                [UIApplication openReviewPageWithAppID:APP_ID];
                
            }];
            [alertController addAction:cancelAction];
            [alertController addAction:okAction];
            [self presentViewController:alertController animated:YES completion:nil];
        }
        
    }];

}
- (void)showAlert{

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:kPickPicMeg preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstOpen"];;
        [[NSUserDefaults standardUserDefaults] synchronize];
    }];
    [alertController addAction:cancelAction];
    [self presentViewController:alertController animated:YES completion:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    DGAccount *acc = [DGAccount currentAccount];
    
    if (![acc.phone isEqualToString:@"13691346958"]) {
        [self judgeVersion];
        
        
        if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"firstOpen"] boolValue]) {
            [self showAlert];
        }
    }
    

//    self.automaticallyAdjustsScrollViewInsets = YES;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.navigationItem.leftBarButtonItem = nil;
    
    _listView = [[PPHomeAlbumListView alloc] init];
    _listView.delegate = self;
    
    [self.view addSubview:_listView];

//    _bottomBar = [[UIView alloc] init];
//    _bottomBar.backgroundColor = [UIColor colorWithRGBHex:0xffdd17];
//    [self.view addSubview:_bottomBar];

//    _createButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    _createButton.imageView.clipsToBounds = NO;
//    _createButton.imageView.contentMode = UIViewContentModeCenter;
//    [_createButton setImage:[UIImage imageNamed:@"icon-add-black"] forState:UIControlStateNormal];
//    [_createButton addTarget:self action:@selector(createButtonDidPressed:) forControlEvents:UIControlEventTouchUpInside];
//    [_bottomBar addSubview:_createButton];

    _topBar = [[UIView alloc] init];
    _topBar.backgroundColor = WHITE;
    [self.view addSubview:_topBar];
    
    _topBarLine = [[UIImageView alloc] init];
    _topBarLine.backgroundColor = PPNavBarLineColor;
    _topBarLine.frame = CGRectMake(0,64, SCREEN_WIDTH, 0.5);
    [self.view addSubview:_topBarLine];
    
    [_topBar addSubview:self.cameraButton];

    _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _searchButton.contentEdgeInsets = UIEdgeInsetsMake(6, 6, 6, 6);
    [_searchButton setImage:[UIImage imageNamed:@"nav_home_setting"] forState:UIControlStateNormal];
    [_searchButton addTarget:self action:@selector(searchButtonDidPressed:) forControlEvents:UIControlEventTouchUpInside];
    [_searchButton sizeToFit];
    [_topBar addSubview:_searchButton];

    
    //修改成 +
//    _cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];
////    _addBtn.contentEdgeInsets = UIEdgeInsetsMake(6, 6, 6, 6);
//    _cameraButton.contentEdgeInsets = UIEdgeInsetsMake(3, 0,0, 0);
//    [_cameraButton setImage:[UIImage imageNamed:@"icon-add-black"/*@"icon-nav-camera"*/] forState:UIControlStateNormal];
//    _cameraButton.frame = CGRectMake(SCREEN_WIDTH - 44,20,44, 44);
//     [_cameraButton addTarget:self action:@selector(createButtonDidPressed:) forControlEvents:UIControlEventTouchUpInside];
////    [_addBtn sizeToFit];
//    _cameraButton.hidden = YES;
//    [_topBar addSubview:_cameraButton];

    __weak typeof(self)weakSelf = self;
    _whiteLogoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo-nav-black"]];
    _whiteLogoView.backgroundColor = [UIColor clearColor];
    _whiteLogoView.clipsToBounds = NO;
    _whiteLogoView.contentMode = UIViewContentModeCenter;
    [_whiteLogoView setActionBlock:^(UIControl *control) {

        [weakSelf dismissSearchWithCompletion:^{
            [MobClick event:@"12"];
            [weakSelf.listView triggerDismiss];
        }];
    } forEvent:UIControlEventTouchUpInside];
    [_topBar addSubview:_whiteLogoView];

    _blackLogoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo-nav-black"]];
    _blackLogoView.backgroundColor = [UIColor clearColor];
    _blackLogoView.clipsToBounds = NO;
    _blackLogoView.contentMode = UIViewContentModeCenter;
    [_blackLogoView setActionBlock:^(UIControl *control) {
        [weakSelf dismissSearchWithCompletion:^{
            [MobClick event:@"59"];
            [weakSelf.dashboardView triggerDismiss];
        }];
    } forEvent:UIControlEventTouchUpInside];
    [_topBar addSubview:_blackLogoView];

//    _dotView = [[PPHomeDotView alloc] init];
//    _dotView.backgroundColor = [UIColor clearColor];
//    [_whiteLogoView addSubview:_dotView];
//
//    _dashboardView = [[PPHomeDashboardView alloc] init];
//    _dashboardView.delegate = self;
//    [self.view addSubview:_dashboardView];
//
//    _searchView = [[PPHomeAlbumSearchView alloc] init];
//    _searchView.delegate = self;
//    _searchView.alpha = 0;
//    [_searchView.cancelButton addTarget:self action:@selector(searchCancelButtonDidPressed:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:_searchView];
//
//    if(_launchedByNotification) {
//        [self toggleState:PPHomeViewStateDashboard animated:NO completion:nil];
//    } else {
//        [self toggleState:PPHomeViewStateAlbum animated:NO completion:nil];
//    }

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveUnreadMessageSummaryDidChangeNotification) name:PPUnreadMessageSummaryDidChangeNotification object:nil];
    
    
    if ([PPNetworkManager sharedInstance].networkStatus == PPNetStatusNotReachable) {
        
        
       
    }

}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    _topBar.frame = CGRectMake(0, 0, self.view.width, 63.5);
    _bottomBar.frame = CGRectMake(0, self.view.height - 49, self.view.width, 49);

    _createButton.frame = _bottomBar.bounds;
    

    _searchButton.centerY = 41;
    _searchButton.left = 12;

    _cameraButton.centerY = 41;
    _cameraButton.right = _topBar.width - 12;

    _whiteLogoView.centerX = _topBar.width/2;
    _whiteLogoView.centerY = 42;

    _blackLogoView.centerX = _topBar.width/2;
    _blackLogoView.centerY = 42;

    _dashboardView.frame = CGRectMake(0, _topBar.bottom, self.view.width, self.view.height - _topBar.bottom);
    _listView.frame = CGRectMake(0, _topBar.bottom, self.view.width,SCREEN_HEIGHT-64);
    
    
    _searchView.frame = CGRectMake(0, _topBar.bottom, self.view.width, self.view.height - _topBar.bottom);

//    _dotView.frame = CGRectMake(_blackLogoView.width, -6, 18, 18);
    _dotView.frame = CGRectMake(_blackLogoView.width, -6, 8, 8);
}

- (void)didReceiveUnreadMessageSummaryDidChangeNotification {
    if([self shouldShowsBadgeDot]) {
        [_dotView displayIfNeeded];
    }
}

- (BOOL)shouldShowsBadgeDot {

    if(_state == PPHomeViewStateDashboard) {
        return NO;
    }

    __block NSInteger count = 0;

    [[PPUnreadMessageManager sharedInstance].summaries enumerateObjectsUsingBlock:^(PPUnreadMessageSummaryObject *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
        count += obj.count.integerValue;
    }];

    if(count > 0) {
        return YES;
    }

    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"HomeBadgeDotGuided"]) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HomeBadgeDotGuided"];
        [[NSUserDefaults standardUserDefaults] synchronize];

        return YES;
    }

    return NO;
}

- (void)toggleState:(PPHomeViewState)state animated:(BOOL)animated completion:(void (^)(void))completion {

    return ;
    
    [_listView hideUtilitiesIfNeeded];
    
    if(_state == state) {
        !completion ? : completion();
    }

    if(_state == PPHomeViewStateNone) {
        _dashboardView.bottom = 0;
        _listView.bottom = 0;
    }

    _state = state;

    if([self shouldShowsBadgeDot]) {
        [_dotView displayIfNeeded];
    } else {
        [_dotView dismiss];
    }

    if(animated) {
        dispatch_group_t group = dispatch_group_create();

        if(_state == PPHomeViewStateAlbum) {
            dispatch_group_enter(group);
            [_dashboardView dismissWithDuration:animated ? 0.5 : 0 animated:animated completion:^{
                dispatch_group_leave(group);

                [_dashboardView reset];
            }];
        } else {
            dispatch_group_enter(group);
            [_listView dismissWithDuration:animated ? 0.5 : 0 animated:animated completion:^{
                dispatch_group_leave(group);

                [_listView reset];
            }];
        }

        dispatch_group_enter(group);
        [UIView animateWithDuration:animated ? 0.5 : 0 delay:0 options:UIViewAnimationOptionBeginFromCurrentState|(4 << 16) animations:^{
            [self setNeedsStatusBarAppearanceUpdate];

            if(_state == PPHomeViewStateAlbum) {
                [MobClick event:@"60"];

//                _topBar.backgroundColor = [UIColor colorWithRGBHex:0x1a1a1a];
                 _topBar.backgroundColor = WHITE;
                _bottomBar.alpha = 1;
                _searchButton.alpha = 1;
                _cameraButton.alpha = 1;

                _blackLogoView.alpha = 0;
                _whiteLogoView.alpha = 1;

                _listView.alpha = 1;
                _dashboardView.alpha = 0;
                _topBarLine.hidden = NO;
                [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
            } else if(_state == PPHomeViewStateDashboard) {
                [MobClick event:@"13"];
                _topBar.backgroundColor = [UIColor colorWithRGBHex:0xffdd17];
//                 _topBar.backgroundColor = WHITE;
                _bottomBar.alpha = 0;
                _searchButton.alpha = 0;
                _cameraButton.alpha = 0;

                _blackLogoView.alpha = 1;
                _whiteLogoView.alpha = 0;

                _listView.alpha = 0;
                _dashboardView.alpha = 1;
                _topBarLine.hidden = YES;
//
//                [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
            }
               [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
        } completion:^(BOOL finished) {

            if(state == PPHomeViewStateAlbum) {
                _dashboardView.top = _topBar.bottom;
                [_dashboardView.superview sendSubviewToBack:_dashboardView];
                _dashboardView.alpha = 0;
            } else if(state == PPHomeViewStateDashboard) {
                _listView.top = _topBar.bottom;
                [_bottomBar.superview sendSubviewToBack:_bottomBar];
                [_listView.superview sendSubviewToBack:_listView];
                _listView.alpha = 0;
            }
            
            dispatch_group_leave(group);
        }];
        
        dispatch_group_notify(group, dispatch_get_main_queue(), ^{
            !completion ? : completion();
        });
    } else {
        if(_state == PPHomeViewStateAlbum) {
            [_dashboardView dismissWithDuration:animated ? 1 : 0 animated:animated completion:^{
                [_dashboardView reset];
            }];
        } else {
            [_listView dismissWithDuration:animated ? 1 : 0 animated:animated completion:^{
                [_listView reset];
            }];
        }

        [self setNeedsStatusBarAppearanceUpdate];

        if(_state == PPHomeViewStateAlbum) {
            [MobClick event:@"60"];

//            _topBar.backgroundColor = [UIColor colorWithRGBHex:0x1a1a1a];
            _topBar.backgroundColor = WHITE;
            _bottomBar.alpha = 1;
            _searchButton.alpha = 1;
            _cameraButton.alpha = 1;

            _blackLogoView.alpha = 0;
            _whiteLogoView.alpha = 1;

            _listView.alpha = 1;
            _dashboardView.alpha = 0;
            _topBarLine.hidden = NO;
        } else if(_state == PPHomeViewStateDashboard) {
            [MobClick event:@"13"];
            _topBar.backgroundColor = [UIColor colorWithRGBHex:0xffdd17];
//             _topBar.backgroundColor = WHITE;
            _bottomBar.alpha = 0;
            _searchButton.alpha = 0;
            _cameraButton.alpha = 0;

            _blackLogoView.alpha = 1;
            _whiteLogoView.alpha = 0;

            _listView.alpha = 0;
            _dashboardView.alpha = 1;
            _topBarLine.hidden = YES;
        }

        if(state == PPHomeViewStateAlbum) {
            _dashboardView.top = _topBar.bottom;
            [_dashboardView.superview sendSubviewToBack:_dashboardView];
            _dashboardView.alpha = 0;
        } else if(state == PPHomeViewStateDashboard) {
            _listView.top = _topBar.bottom;
            [_bottomBar.superview sendSubviewToBack:_bottomBar];
            [_listView.superview sendSubviewToBack:_listView];
            _listView.alpha = 0;
        }

        !completion ? : completion();
    }
}

#pragma mark -

- (void)displaySearchWithCompletion:(void (^)(void))completion {
    _isSearchShown = YES;

    [_searchView.superview bringSubviewToFront:_searchView];

    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        _searchView.alpha = 1;
    } completion:^(BOOL finished) {
        [_listView hideUtilitiesIfNeeded];

        [_searchView becomeFirstResponder];

        !completion ?: completion();
    }];
}

- (void)dismissSearchWithCompletion:(void (^)(void))completion {
    _isSearchShown = NO;
    [_searchView resignFirstResponder];
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        _searchView.alpha = 0;
    } completion:^(BOOL finished) {
        !completion ?: completion();
    }];
}

- (void)searchCancelButtonDidPressed:(UIButton *)sender {
    [self dismissSearchWithCompletion:nil];
}

///设置
- (void)searchButtonDidPressed:(UIButton *)sender {
    [MobClick event:@"10"];
    
//    PPSettingViewController *settingViewController = [[UIStoryboard storyboardWithName:@"Setting" bundle:nil] instantiateViewControllerWithIdentifier:@"PPSettingViewController"];
    
    PPSettingViewController *settingViewController = [[PPSettingViewController alloc] init];
    [self.navigationController pushViewController:settingViewController animated:YES];
    
//    if(_isSearchShown == NO) {
//        [self displaySearchWithCompletion:nil];
//    } else {
//        [self dismissSearchWithCompletion:nil];
//    }
}

- (void)cameraButtonDidPressed:(UIButton *)sender {
    [_listView hideUtilitiesIfNeeded];

    [MobClick event:@"11"];
    PPCameraViewController *cameraViewController = [[PPCameraViewController alloc] init];
    cameraViewController.cameraDelegate = self;
    [self presentViewController:cameraViewController animated:YES completion:nil];
}
//- (PPHomePickerView *)pickerView{
//
//    if (!_pickerView) {
//        _pickerView = [[NSBundle mainBundle] loadNibNamed:@"PPHomePickerView" owner:nil options:nil].firstObject;
//        
//        _pickerView.frame = CGRectMake(0, _listView.height - _pickerView.height, _listView.width, _pickerView.height);
//    }
//    return _pickerView;
//}
//- (DGPopoverView *)poverView{
//
//    if (!_poverView) {
//        _poverView = [[DGPopoverView alloc] initWithContainerView:_listView contentView:self.pickerView options:DGPopoverViewAnimationOptionUpward backgroundStyle:DGPopoverViewBackgroundStyleDimmed];
//        self.poverView.isClickBg = YES;
//        self.poverView.delegate = self;
//        __weak typeof(self)weakSelf = self;
//        
//        [self.pickerView.createButton setActionBlock:^(UIControl *control) {
//            [weakSelf.poverView dismissAnimated:YES completion:^{
//                [MobClick event:@"19"];
//                PPAlbumContentViewController *createViewController = [[UIStoryboard storyboardWithName:@"Album" bundle:nil] instantiateViewControllerWithIdentifier:@"PPAlbumContentViewController"];
//                createViewController.type = PPAlbumContentViewControllerTypeCreate;
//                [weakSelf.navigationController pushViewController:createViewController animated:YES];
//            }];
//        } forControlEvents:UIControlEventTouchUpInside];
//        
//        [self.pickerView.addButton setActionBlock:^(UIControl *control) {
//            [weakSelf.poverView  dismissAnimated:YES completion:^{
//                [MobClick event:@"20"];
//                PPAssetsPickerViewController *assetsViewController = [[PPAssetsPickerViewController alloc] init];
//                assetsViewController.delegate = weakSelf;
//                assetsViewController.userInfo = @{@"type" : @"addImage"};
//                [weakSelf.navigationController pushViewController:assetsViewController animated:YES];
//            }];
//        } forControlEvents:UIControlEventTouchUpInside];
//        
//        [self.pickerView.grabButton setActionBlock:^(UIControl *control) {
//            [weakSelf.poverView  dismissAnimated:YES completion:^{
//                [MobClick event:@"21"];
//                
//                //            PPWebGrabViewController *grabViewController = [[PPWebGrabViewController alloc] init];
//                //            [weakSelf.navigationController pushViewController:grabViewController animated:YES];
//            }];
//        } forControlEvents:UIControlEventTouchUpInside];
//        
//        self.poverView .willDisplayBlock = ^{
//            
//            [weakSelf.createButton.superview bringSubviewToFront:weakSelf.createButton];
//            
//            [weakSelf.createButton setActionBlock:^(UIControl *control) {
//                [weakSelf.poverView  dismissAnimated:YES completion:nil];
//            } forControlEvents:UIControlEventTouchUpInside];
//            
//            [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
//                weakSelf.createButton.imageView.transform = CGAffineTransformMakeRotation(M_PI/4);
//            } completion:nil];
//            
//        };
//        //        self.poverView .willDismissBlock = ^{
//        //
//        //            [weakSelf.createButton setActionBlock:^(UIControl *control) {
//        //                [weakSelf createButtonDidPressed:(UIButton *)control];
//        //            } forControlEvents:UIControlEventTouchUpInside];
//        //
//        //            [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
//        //                weakSelf.createButton.imageView.transform = CGAffineTransformIdentity;
//        //            } completion:nil];
//        //
//        //        };
//        
//        [_poverView displayAnimated:YES completion:nil];
//        
//        [_listView hideUtilitiesIfNeeded];
//    }
//    return _poverView;
//}
- (void)createButtonDidPressed:(UIButton *)sender {
    
//    [self.sheetView showInView:self.view];
    
    [self selectPhoto];
}
- (PPSheetView *)sheetView{
    if (!_sheetView) {
        _sheetView = [[PPSheetView alloc] init];
        _sheetView.delegate = self;
        _sheetView.items = @[@"创建相册",@"添加图片",@"取消"];
    }
    return _sheetView;
}
///MARK:sheetView delegate
- (void)sheetView:(PPSheetView *)sheetView didSelectedIndex:(NSInteger)index{

    
    switch (index) {
        case 0:{
            [MobClick event:@"19"];
            
            PPAlbumEditContentViewController *createViewController = [[PPAlbumEditContentViewController alloc] init];
            
//            PPAlbumContentViewController *createViewController = [[UIStoryboard storyboardWithName:@"Album" bundle:nil] instantiateViewControllerWithIdentifier:@"PPAlbumContentViewController"];
            createViewController.title = @"创建相册";
            createViewController.type = PPAlbumContentViewControllerTypeCreate;
            [self.navigationController pushViewController:createViewController animated:YES];

        }
            break;
        case 1:{
            [MobClick event:@"20"];
            PPAssetsPickerViewController *assetsViewController = [[PPAssetsPickerViewController alloc] init];
            assetsViewController.delegate = self;
            assetsViewController.userInfo = @{@"type" : @"addImage"};
            [self.navigationController pushViewController:assetsViewController animated:YES];      
        }
            break;
        case 2:
            
            break;
            
        default:
            break;
    }
    
    [sheetView disMissView];
}
///MARK:分享出来的界面
- (void)shareAlbum:(PPAlbumModel *)album title:(NSString *)title subtitle:(NSString *)subtitle url:(NSString *)url image:(UIImage *)image pickpic:(NSString *)pickpic {

    PPAccountProfiles *profiles = DGCurrentAccount.profiles;

    PPAlbumShareView *shareView = [[NSBundle mainBundle] loadNibNamed:@"PPAlbumShareView" owner:nil options:nil].firstObject;
    shareView.frame = CGRectMake(0, 0, self.view.width, self.view.height);
    shareView.alpha = 0;
    shareView.avatarURLString = profiles.avatarURLString;
    shareView.name = profiles.name;
    shareView.account = pickpic;
    shareView.cover = image;
    shareView.title = album.title;
    [self.view addSubview:shareView];

    [shareView updateConstraintsIfNeeded];
    [shareView layoutIfNeeded];

    shareView.titleLabel.hidden = YES;
    UIImage *thumbnail = [shareView.contentView snapshotImage];
    shareView.titleLabel.hidden = NO;
    image = [shareView.contentView snapshotImage];

    UIView *actionView = nil;

    if([[PPSocializationManager sharedInstance] support:PPSocializationTypeWeixin] && [[PPSocializationManager sharedInstance] support:PPSocializationTypeQQ]) {
        actionView = [[[NSBundle mainBundle] loadNibNamed:@"PPAlbumShareActionView" owner:nil options:nil] safeObjectAtIndex:0];
    } else if([[PPSocializationManager sharedInstance] support:PPSocializationTypeWeixin]) {
        actionView = [[[NSBundle mainBundle] loadNibNamed:@"PPAlbumShareActionView" owner:nil options:nil] safeObjectAtIndex:1];
    } else if([[PPSocializationManager sharedInstance] support:PPSocializationTypeQQ]) {
        actionView = [[[NSBundle mainBundle] loadNibNamed:@"PPAlbumShareActionView" owner:nil options:nil] safeObjectAtIndex:2];
    } else {
        actionView = [[[NSBundle mainBundle] loadNibNamed:@"PPAlbumShareActionView" owner:nil options:nil] safeObjectAtIndex:3];
    }

    actionView.frame = CGRectMake(0, self.view.height - actionView.height - _createButton.height, self.view.width, actionView.height);

    DGPopoverView *popoverView = [[DGPopoverView alloc] initWithContainerView:self.view contentView:actionView options:DGPopoverViewAnimationOptionUpward backgroundStyle:DGPopoverViewBackgroundStyleNone];

    __weak typeof(self)weakSelf = self;
    __weak typeof(popoverView)weakPopover = popoverView;

    if([actionView respondsToSelector:@selector(wechatButton)]) {
        UIButton *wechatButton = [actionView valueForKey:@"wechatButton"];
        [wechatButton setActionBlock:^(UIControl *control) {
            [weakPopover dismissAnimated:YES completion:^{
                [[PPSocializationManager sharedInstance] shareTitle:title subtitle:subtitle url:url image:image thumbnail:thumbnail type:PPSocializationShareTypeWeixinChat];
            }];
        } forControlEvents:UIControlEventTouchUpInside];
    }

    if([actionView respondsToSelector:@selector(circleButton)]) {
        UIButton *circleButton = [actionView valueForKey:@"circleButton"];
        [circleButton setActionBlock:^(UIControl *control) {
            [weakPopover dismissAnimated:YES completion:^{
                [[PPSocializationManager sharedInstance] shareTitle:title subtitle:subtitle url:url image:image thumbnail:thumbnail type:PPSocializationShareTypeWeixinCircle];
            }];
        } forControlEvents:UIControlEventTouchUpInside];
    }

    if([actionView respondsToSelector:@selector(weiboButton)]) {
        UIButton *weiboButton = [actionView valueForKey:@"weiboButton"];
        [weiboButton setActionBlock:^(UIControl *control) {
            [weakPopover dismissAnimated:YES completion:^{
                [[PPSocializationManager sharedInstance] shareTitle:title subtitle:subtitle url:url image:image thumbnail:thumbnail type:PPSocializationShareTypeWeibo];
            }];
        } forControlEvents:UIControlEventTouchUpInside];
    }

    if([actionView respondsToSelector:@selector(qqButton)]) {
        UIButton *qqButton = [actionView valueForKey:@"qqButton"];
        [qqButton setActionBlock:^(UIControl *control) {
            [weakPopover dismissAnimated:YES completion:^{
                [[PPSocializationManager sharedInstance] shareTitle:title subtitle:subtitle url:url image:image thumbnail:thumbnail type:PPSocializationShareTypeQQChat];
            }];
        } forControlEvents:UIControlEventTouchUpInside];
    }

    if([actionView respondsToSelector:@selector(cancelButton)]) {
        UIButton *cancelButton = [actionView valueForKey:@"cancelButton"];
        [cancelButton setActionBlock:^(UIControl *control) {
            [weakPopover dismissAnimated:YES completion:nil];
        } forControlEvents:UIControlEventTouchUpInside];
    }

    popoverView.willDisplayBlock = ^{

        [weakSelf.view bringSubviewToFront:shareView];

        [weakSelf.view bringSubviewToFront:weakPopover];

        [weakSelf.view bringSubviewToFront:weakSelf.bottomBar];

        [weakSelf.bottomBar bringSubviewToFront:weakSelf.createButton];

        [weakSelf.createButton setActionBlock:^(UIControl *control) {
            [weakPopover dismissAnimated:YES completion:nil];
        } forControlEvents:UIControlEventTouchUpInside];

        [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
            weakSelf.createButton.imageView.transform = CGAffineTransformMakeRotation(M_PI/4);
            shareView.alpha = 1;
        } completion:nil];

    };

    popoverView.willDismissBlock = ^{

        [weakSelf.createButton setActionBlock:^(UIControl *control) {
            [weakSelf createButtonDidPressed:(UIButton *)control];
        } forControlEvents:UIControlEventTouchUpInside];

        [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
            weakSelf.createButton.imageView.transform = CGAffineTransformIdentity;
            shareView.alpha = 0;
        } completion:^(BOOL finished) {
            [shareView removeFromSuperview];
        }];

    };

    [popoverView displayAnimated:YES completion:nil];
}

- (BOOL)prefersNavigationBarHidden {
    return YES;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    if(_state == PPHomeViewStateAlbum) {
        return UIStatusBarStyleLightContent;
    } else {
        return UIStatusBarStyleDefault;
    }
}

#pragma mark - PPHomeDashboardViewDelegate

- (void)dashboardView:(PPHomeDashboardView *)dashboardView didSelectBadgeCell:(PPHomeDashboardViewBadgeCell *)badgeCell {
    switch(badgeCell.type) {
        case PPMainViewBadgeTypeSetting: {
            [MobClick event:@"67"];
            PPSettingViewController *settingViewController = [[UIStoryboard storyboardWithName:@"Setting" bundle:nil] instantiateViewControllerWithIdentifier:@"PPSettingViewController"];
            [self.navigationController pushViewController:settingViewController animated:YES];
            break;
        }

        case PPMainViewBadgeTypeContact: {
            [MobClick event:@"66"];
            PPContactsSegmentedViewController *contactsViewController = [[PPContactsSegmentedViewController alloc] init];
            [self.navigationController pushViewController:contactsViewController animated:YES];

            break;
        }

        case PPMainViewBadgeTypeFound: {
            [MobClick event:@"64"];
            PPFoundViewController *foundViewController = [[UIStoryboard storyboardWithName:@"Found" bundle:nil] instantiateViewControllerWithIdentifier:@"PPFoundViewController"];
            [self.navigationController pushViewController:foundViewController animated:YES];

            break;
        }

        case PPMainViewBadgeTypeFavour: {
            [MobClick event:@"65"];
            PPMyFavouritesViewController *myFavouritesViewController = [[PPMyFavouritesViewController alloc] init];
            [self.navigationController pushViewController:myFavouritesViewController animated:YES];

            break;
        }

        case PPMainViewBadgeTypeFriend: {
            [MobClick event:@"62"];
            PPFriendsTimelineViewController *friendsTimelineViewController = [[PPFriendsTimelineViewController alloc] init];
            [self.navigationController pushViewController:friendsTimelineViewController animated:YES];
            break;
        }

        case PPMainViewBadgeTypeMiao: {
            [MobClick event:@"63"];
            PPMiaoTimelineViewController *miaoTimelineViewController = [[PPMiaoTimelineViewController alloc] init];
            [self.navigationController pushViewController:miaoTimelineViewController animated:YES];
            break;
        }

        case PPMainViewBadgeTypeHome: {
            [MobClick event:@"61"];
            PPProfileViewController *profileViewController = [[PPProfileViewController alloc] init];
            profileViewController.userID = DGCurrentAccount.userID;
            [self.navigationController pushViewController:profileViewController animated:YES];

            break;
        }

        default:
            break;
    }
}

- (void)dashboardViewDidTriggerToggling:(PPHomeDashboardView *)dashboardView {
    [self toggleState:PPHomeViewStateAlbum animated:YES completion:nil];
}



///MARK: push 电子书
#pragma mark - PPHomeAlbumListViewDelegate
//- (void)listView:(PPHomeAlbumListView *)listView didSelectEbookAlbum:(PPAlbumModel *)album{
//
//    PPShareTemplateController *shareTemplateVc = [[PPShareTemplateController alloc] init];
//
//    shareTemplateVc.homeAlbumModel = [self saveAlbumInfo:album];
//    
//    shareTemplateVc.normalAlbumModel = [self saveAlbumInfo:album];
//    
//    if (shareTemplateVc.homeAlbumModel.pictures.count > 0) {
//        for (PPPictureModel *pic in shareTemplateVc.homeAlbumModel.pictures) {
//            PPLog(@"打印%@",pic);
//
//            if (pic.picKey.length <= 0) {
//                [self.navigationController.view toastMessage:@"相册图片正在努力上传,请稍等"];
//                return;
//            }
//        }
//    }
//    [MobClick event:@"17"];
//    __block NSError *error_ = nil;
//    __block UIImage *image_ = nil;
//    __block NSString *imageString = nil;
//    __block PPHomeAlbumModel *albumM = nil;
//    dispatch_group_t group = dispatch_group_create();
//    __weak typeof(self)weakSelf = self;
//    dispatch_group_enter(group);
//    [PPNetworkService getShareInfoWithAlbumID:album.albumID callback:^(id data, NSError *error) {
//        __strong typeof(weakSelf)strongSelf = weakSelf;
//        NSDictionary *dict = data;
//        if(strongSelf == nil) {
//            return;
//        }
//        if(error == nil) {
//            albumM = [PPHomeAlbumModel yy_modelWithDictionary:dict];
//            albumM.auuid = album.auuid;
//        } else {
//            error_ = error;
//        }
//        dispatch_group_leave(group);
//    }];
//    
//    dispatch_group_enter(group);
//    [album queryAlbumCoverImageWithCompletion:^(UIImage *image,NSString *coverURL, NSError *error) {
//        if(error == nil) {
//            image_ = image;
//            imageString = coverURL;
//            albumM.coverURL = coverURL;
//            
//            shareTemplateVc.coverImage = image;
//            
//            shareTemplateVc.normalAlbumModel.coverImage = image;
//            
//        } else {
//            error_ = error;
//        }
//        dispatch_group_leave(group);
//    }];
//    
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
//    
//    dispatch_group_notify(group, dispatch_get_main_queue(), ^{
//        if(image_ && albumM) {
//            
//            albumM.image = image_;
//
//            shareTemplateVc.albumModel = albumM;
////            PPBaseNavigationViewController *nav = [[PPBaseNavigationViewController alloc] initWithRootViewController:shareTemplateVc];
////            [self presentViewController:nav animated:YES completion:nil];
//            
//
//            shareTemplateVc.albumM = album;
//            //查询是生成过电子书 (根据本地缓存模板文件)
//            NSMutableArray *templateArr = [NSMutableArray arrayWithContentsOfFile:kTemplatePlist];
//            
//            if (templateArr.count <=0) {
//                  [self.navigationController pushViewController:shareTemplateVc animated:NO];
//                [hud hide:YES];
//                return ;
//            }
//            
//            
//            NSMutableDictionary *dict = [NSMutableDictionary dictionary];
//            NSMutableDictionary *pageInfoDict = [NSMutableDictionary dictionary];
//            [pageInfoDict setSafeObject:@(1) forKey:@"page"];
//            [pageInfoDict setSafeObject:@(100) forKey:@"rows"];
//            [dict setSafeObject:album.albumID forKey:@"albumId"];
//            [dict setSafeObject:pageInfoDict forKey:@"pageInfo"];
//            [dict setSafeObject:[album.order integerValue]==1?@"desc":@"asc" forKey:@"order"];
//            
//                [PPNetworkService gettemplateEbookListWithparams:dict callback:^(id data, NSError *error) {
//                    
//                    PPLog(@"历史电子书%@,%@",data,albumM.coverURL);
//                    
//                    NSString *coverURL;
//                    if (data && [data[@"total"] integerValue]>0) {
//                        NSMutableArray *ebooks = [NSMutableArray array];
//                    
//                        NSArray *arr = data[@"rows"];
//                        
//                        //电子书没有封面 查找最小的pictrueid为封面
//                        NSInteger coverPictureID = NSIntegerMax;
//                        
//                        PPHomeEbookModel *tempCoverM;
//                        for (NSDictionary *dict in arr) {
//                            PPHomeEbookModel *ebookM = [PPHomeEbookModel yy_modelWithDictionary:dict];
//                            ebookM.picType = 2;
//                            [ebooks insertObject:ebookM atIndex:0];
//                            
//                            if (coverPictureID > [ebookM.pictureId integerValue]) {
//                                coverPictureID = [ebookM.pictureId integerValue];
//                                tempCoverM = [PPHomeEbookModel yy_modelWithDictionary:dict];
//                                tempCoverM.pictureId = [NSString stringWithFormat:@"%zd",coverPictureID];
//                                tempCoverM.picType = 1;
//                                tempCoverM.url = [albumM.coverURL stringByReplacingOccurrencesOfString:PPPicHost withString:@""];
//                            }
//                        }
//                        
//                        if (data[@"common"]) {
//                            PPHomeEbookModel *coverM = [PPHomeEbookModel yy_modelWithDictionary:data[@"common"]];
//                            coverURL = coverM.url;
//                            coverM.picType = 1;
//                            [ebooks insertObject:coverM atIndex:0];
//                        }else{
//                            //加入封面
//                            [ebooks insertObject:tempCoverM atIndex:0];
//                            //更新封面电子书
//                            NSDictionary *coverDic = @{
//                                                       @"pictureId":@([tempCoverM.pictureId integerValue]),
//                                                       @"url":tempCoverM.url,
//                                                       @"picType":@(1),
//                                                       @"operateType":@(1),
//                                                       };
//                            NSDictionary *ebookDic = @{
//                                                       @"albumId":tempCoverM.albumId,
//                                                       @"pics":@[coverDic],
//                                                       };
//                            [self updatePramsparam:ebookDic];
//                            
//                        }
//
//                        shareTemplateVc.eBookModels = ebooks;
//                        PPHomeEbookModel *tempM = [ebooks lastObject];
//                        if (templateArr.count > 0) {
//                            //查询到了电子相册 且本地有模板数据 才会显示电子相册 否则显示默认模板
//                            for (int i = 0; i<templateArr.count; i++) {
//                                PPTemplateModel *temp = [PPTemplateModel yy_modelWithDictionary:templateArr[i]];
//                                if ([temp.eBookTemplateId isEqualToString:tempM.eBookTemplateId]) {
//                                    //本地有模板数据
//                                    for (NSDictionary *ebookAlbum  in temp.albums) {
//                                           PPEbookAlbum *ebookA = [PPEbookAlbum yy_modelWithDictionary:ebookAlbum];
//                                        if (ebookA.albumID == album.albumID) {
//                                            shareTemplateVc.eBookModel = temp;
//                                            ebookA.downloadType = PPTemplateDownLoadTypeEmploy;
//                                            [templateArr replaceObjectAtIndex:i withObject:[temp yy_modelToJSONObject]];
//                                        }
//                                    }
//                                    
//                                }
//                            }
//                            if (shareTemplateVc.eBookModel) {
//                                 [templateArr writeToFile:kTemplatePlist atomically:YES];
//                            }
//                        }
//                        
//                    }
//                    if (coverURL) {
//                        dispatch_group_t group1 =dispatch_group_create();
//                        dispatch_group_enter(group1);
//                        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",PPPicHost,coverURL]] options:SDWebImageDownloaderIgnoreCachedResponse progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//                            
//                        } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
//                            if (image) {
////                                shareTemplateVc.albumModel.image =  image;
//                                shareTemplateVc.eBookCoverImage = image;
//                            }
//                            if (finished) {
//                                dispatch_group_leave(group1);
//                            }
//                        }];
//                        dispatch_group_notify(group1,dispatch_get_main_queue(), ^(){
//                              [hud hide:YES];
//                            [self.navigationController pushViewController:shareTemplateVc animated:NO];
//                            
//                        });
//                    
//                    }else{
//                        [hud hide:YES];
//                        [self.navigationController pushViewController:shareTemplateVc animated:NO];
//                    }
//                }];
//
//        } else {
//            [hud hide:YES];
//            [self.navigationController.view toastMessage:error_.networkPrompt];
//        }
//    });
//   }
- (void)listViewDidSelectCreateAlbum:(PPHomeAlbumListView *)listView {
    [MobClick event:@"14"];
    
    [self selectPhoto];
    
//         PPAlbumEditContentViewController *createViewController = [[PPAlbumEditContentViewController alloc] init];
//    PPAlbumContentViewController *createViewController = [[UIStoryboard storyboardWithName:@"Album" bundle:nil] instantiateViewControllerWithIdentifier:@"PPAlbumContentViewController"];
//    createViewController.type = PPAlbumContentViewControllerTypeCreate;
//    [self.navigationController pushViewController:createViewController animated:YES];

}

- (void)listViewDidTriggerToggling:(PPHomeAlbumListView *)listView {
    [self toggleState:PPHomeViewStateDashboard animated:YES completion:nil];
}

///MARK:相册列表
- (void)listView:(PPHomeAlbumListView *)listView didSelectAlbum:(PPAlbumModel *)album {
    [MobClick event:@"22"];
    PPAlbumPreviewViewController *imageViewController = [[PPAlbumPreviewViewController alloc] init];
    imageViewController.album = album;
    [self.navigationController pushViewController:imageViewController animated:YES];
}

- (void)listView:(PPHomeAlbumListView *)listView didSelectDeleteAlbum:(PPAlbumModel *)album {
    [MobClick event:@"18"];
    DGBlockActionSheet *actionSheet = [DGBlockActionSheet actionSheetWithTitle:@"确认要删除这个相册么"];
    [actionSheet addDestructiveButtonWithTitle:@"删除" clickBlock:^{
        [[PPAlbumManager sharedInstance] offlineDeleteAlbumWithAlbumUUID:album.auuid];
        
    [PPNetworkService deleteAlbumeBookWithAlbumID:album.albumID callback:^(id data, NSError *error) {
            
        }];
    }];
    [actionSheet addCancelButtonWithTitle:@"取消"];
    [actionSheet showInView:self.view];
}

- (void)listView:(PPHomeAlbumListView *)listView didSelectShareAlbum:(PPAlbumModel *)album {

    [MobClick event:@"17"];
    __block NSError *error_ = nil;
    __block NSString *title = nil;
    __block NSString *subtitle = nil;
    __block NSString *url = nil;
    __block UIImage *image_ = nil;
    __block NSString *pickpic = nil;

    dispatch_group_t group = dispatch_group_create();

    __weak typeof(self)weakSelf = self;

    dispatch_group_enter(group);
    [PPNetworkService getShareInfoWithAlbumID:album.albumID callback:^(id data, NSError *error) {
        __strong typeof(weakSelf)strongSelf = weakSelf;

        if(strongSelf == nil) {
            return;
        }

        if(error == nil) {
            title = [data validStringForKey:@"title"];
            subtitle = [data validStringForKey:@"title2"];
            url = [data validStringForKey:@"url"];
            pickpic = [data validStringForKey:@"pickpic"];
        } else {
            error_ = error;
        }
        dispatch_group_leave(group);

    }];

    dispatch_group_enter(group);
    [album queryCoverImageWithCompletion:^(UIImage *image, NSError *error) {
        if(error == nil) {
            image_ = image;
        } else {
            error_ = error;
        }

        dispatch_group_leave(group);
    }];

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];

    dispatch_group_notify(group, dispatch_get_main_queue(), ^{

        [hud hide:YES];

        if(error_ != nil) {
            [self.navigationController.view toastMessage:error_.networkPrompt];
        } else {
            [self shareAlbum:album title:title subtitle:subtitle url:url image:image_ pickpic:pickpic];
        }
    });
}

- (void)listView:(PPHomeAlbumListView *)listView didSelectEditAlbum:(PPAlbumModel *)album {
    [MobClick event:@"16"];
    
         PPAlbumEditContentViewController *contentViewController = [[PPAlbumEditContentViewController alloc] init];
//    PPAlbumContentViewController *contentViewController = [[UIStoryboard storyboardWithName:@"Album" bundle:nil] instantiateViewControllerWithIdentifier:@"PPAlbumContentViewController"];
    contentViewController.type = PPAlbumContentViewControllerTypeEdit;
    contentViewController.auuid = album.auuid;
    [self.navigationController pushViewController:contentViewController animated:YES];
}

#pragma mark - PPAssetsViewControllerDelegate

- (void)assetsPickerViewControllerDidPressConfirm:(PPAssetsPickerViewController *)assetsPickerViewController {
    [self.navigationController popToViewController:self animated:YES];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        PPAlbumContentViewDataSource *dataSource = [[PPAlbumContentViewDataSource alloc] init];

        for(ALAsset *asset in assetsPickerViewController.selectedAssets) {
            PPAbstractArtwork *artwork = [[PPAbstractArtwork alloc] init];
            artwork.uuid = [NSString uuid];
            artwork.image = [asset.image fixOrientation];
            artwork.thumbnail = asset.thumbnailImage;
            artwork.created = YES;

            [dataSource.images addObject:artwork];
            [dataSource.insertedImages addObject:artwork];
        }

        PPAlbumPictureInsertionViewController *insertionViewController = [[UIStoryboard storyboardWithName:@"Album" bundle:nil] instantiateViewControllerWithIdentifier:@"PPAlbumPictureInsertionViewController"];
        insertionViewController.dataSource = dataSource;
        [self.navigationController pushViewController:insertionViewController animated:YES];
    });
}

- (void)assetsPickerViewControllerDidPressCancel:(PPAssetsPickerViewController *)assetsPickerViewController {
    [self.navigationController popToViewController:self animated:YES];
}

#pragma mark - PPHomeAlbumSearchViewDelegate

- (void)searchView:(PPHomeAlbumSearchView *)searchView didSelectAlbum:(PPAlbumModel *)album {
    PPAlbumPreviewViewController *imageViewController = [[PPAlbumPreviewViewController alloc] init];
    imageViewController.album = album;
    [self.navigationController pushViewController:imageViewController animated:YES];
}

#pragma mark - PPCameraViewControllerDelegate

- (void)cameraViewControllerDidPressCancel:(PPCameraViewController *)cameraViewController {
    [cameraViewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)cameraViewController:(PPCameraViewController *)cameraViewController didSelectImages:(NSArray<UIImage *> *)images {
    PPAlbumContentViewDataSource *dataSource = [[PPAlbumContentViewDataSource alloc] init];

    [images enumerateObjectsUsingBlock:^(UIImage *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
        PPAbstractArtwork *artwork = [[PPAbstractArtwork alloc] init];
        artwork.image = [obj fixOrientation];
        artwork.uuid = [NSString uuid];
        [dataSource.images addObject:artwork];
        [dataSource.insertedImages addObject:artwork];
    }];

    PPAlbumPictureInsertionViewController *insertionViewController = [[UIStoryboard storyboardWithName:@"Album" bundle:nil] instantiateViewControllerWithIdentifier:@"PPAlbumPictureInsertionViewController"];
    insertionViewController.dataSource = dataSource;

    [cameraViewController dismissViewControllerAnimated:YES completion:^{
        [self.navigationController pushViewController:insertionViewController animated:YES];
    }];
}

- (void)listView:(PPHomeAlbumListView *)listView listAlbumData:(NSArray *)albums{
    
    if (albums.count > 0) {
        self.cameraButton.hidden = NO;
    }else{
        self.cameraButton.hidden = YES;
    }
    
    
    BOOL albumOpen = [[[NSUserDefaults standardUserDefaults] objectForKey:kFistToast] boolValue] ;
    
    if (albums.count > 0 && !albumOpen) {
        [self guideOperation:@"可以直接去分享啦!"];
        [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:kFistToast];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}
- (UIWindow *)lastWindow { NSArray *windows = [UIApplication sharedApplication].windows; for(UIWindow *window in [windows reverseObjectEnumerator]) { if ([window isKindOfClass:[UIWindow class]] &&
                                                                                                                                                          
                                                                                                                                                          CGRectEqualToRect(window.bounds, [UIScreen mainScreen].bounds))
    
    return window;
    
}
    
    return [UIApplication sharedApplication].keyWindow;
    
}

#pragma mark -首次进如显示 弹框
- (UIButton *)coverEbookBtn{

    if (!_coverEbookBtn) {
        _coverEbookBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_coverEbookBtn setImage:[UIImage imageNamed:@"book_icon"] forState:UIControlStateNormal];
    }
    return _coverEbookBtn;
}
- (PPCoverAlertView *)coverAlert{

    if (!_coverAlert) {
        _coverAlert = [PPCoverAlertView coverAlertView];
        WEAKSELF
        _coverAlert.BlockClick = ^{
          
            [weakSelf hiddenCover];
        };
    }
    return _coverAlert;
}
- (void)hiddenCover{
    
    [self.coverView removeFromSuperview];
    self.coverView = nil;
}
- (void)guideOperation:(NSString *)mark{
    
    self.coverView = [[UIView alloc] init];
     self.coverView .frame = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
     self.coverView .backgroundColor = [UIColor colorWithWhite:0.f alpha:0.7];
    [self.view.window addSubview: self.coverView];
    
    self.coverEbookBtn.frame = CGRectMake(SCREEN_WIDTH - 10 - 35, 104, 35, 35);
    [self.coverView addSubview:self.coverEbookBtn];
    
    UIImageView *img = [[UIImageView alloc] init];
    img.userInteractionEnabled = YES;
    img.frame = CGRectMake(self.view.width-210+4,91+64-15, 200, 40);
    img.image = [UIImage imageNamed:@"LongPressMessageBkg"];
    self.coverAlert.leftLabel.text = mark;
    self.coverAlert.frame = CGRectMake(13,7,180, 30);
    
    [img addSubview:self.coverAlert];
    
//    UILabel *label = [[UILabel alloc] init];
//    
//    label.backgroundColor = RED;
//    label.textAlignment = NSTextAlignmentLeft;
//    label.text = mark;
//    label.textColor = BLACK;
//    label.font = PPFONTSIZE(14.f);
//    label.frame = CGRectMake(15, 4,[label rectWidthWithText:label.text height:36 font:label.font]+15, 36);
//    [img addSubview:label];
//    
//    
//    UIButton *alertBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [alertBtn setTitle:@"知道了" forState:UIControlStateNormal];
//    alertBtn.titleLabel.font = PPFONTSIZE(14.0f);
//    alertBtn.backgroundColor = YELLOW;
//    alertBtn.frame = CGRectMake(CGRectGetWidth(label.frame)+15, 4,35, 30);
//    alertBtn.layer.masksToBounds = YES;
//    alertBtn.layer.cornerRadius = 3;
//    [img addSubview:alertBtn];
    
    [self.coverView  addSubview:img];
    
    
    
    
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [UIView beginAnimations:nil context:nil];
//        [UIView setAnimationDelegate:self];
//        [UIView setAnimationDuration:1.0f];
//        [img setAlpha:0.0f];
//        [UIView commitAnimations];
//    });

}
//头像上传
- (void)setUploadFile:(PPUploaderFile *)file{
    
    PPAbstractArtwork *artwork = [[PPAbstractArtwork alloc] init];
    artwork.image = file.image;
    artwork.uuid = [NSString uuid];
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        
        [[PPImageTransaction sharedInstance] prepareTransactionWithArtwork:artwork completion:^{
            
            __weak typeof(self)weakSelf = self;
            [PPNetworkService updateAvatarWithFileName:artwork.transactionIdentifier callback:^(id data, NSError *error) {
                
                __strong typeof(weakSelf)strongSelf = weakSelf;
                
                if(strongSelf == nil) {
                    return;
                }
                if(error == nil) {
                    NSString *key = [data validStringForKey:@"key"];
                    NSString *token = [data validStringForKey:@"uploadToken"];
                    NSString *host = [data validStringForKey:@"host"];
                    
                    [[PPImageTransaction sharedInstance] beginTransactionWithIdentifier:artwork.transactionIdentifier key:key token:token completion:^(NSError *error) {
                        __strong typeof(weakSelf)strongSelf = weakSelf;
                        
                        if(strongSelf == nil) {
                            return;
                        }
                        if(error == nil) {
                            
                            PPAccountProfiles *profiles = [PPAccountManager sharedInstance].account.profiles;
                            profiles.avatar = key;
                            profiles.avatarHost = host;
                            [profiles.managedObjectContext saveContext];
                            
                            NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
                            [userInfo setSafeObject:host forKey:@"avatarHost"];
                            [userInfo setSafeObject:key forKey:@"avatarKey"];
                            
                            [[NSNotificationCenter defaultCenter] postNotificationName:PPAccountProfilesAvatarDidChangeNotification object:profiles.avatarURLString userInfo:userInfo];
                        } else {
                            [strongSelf.navigationController.view toastMessage:error.networkPrompt];
                        }
                    }];
                    
                } else {
                    [hud hide:YES];
                    
                    [strongSelf.navigationController.view toastMessage:error.networkPrompt];
                }
            }];
            
        }];

}

- (void)listViewWithCreateAlbum{

    [self selectPhoto];
}
///MARK:调用相册 - HOME
- (void)selectPhoto{
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:50 delegate:self];
    imagePickerVc.naviBgColor = WHITE;
    imagePickerVc.naviTitleColor = BLACK;
    imagePickerVc.naviTitleFont = PPFONT(@"Helvetica-Bold", 17);
    imagePickerVc.barItemTextColor = BLACK;
    imagePickerVc.barItemTextFont = PPFONT(@"Helvetica-Bold", 16);
    imagePickerVc.allowPickingVideo = NO;
//    imagePickerVc.sortAscendingByModificationDate = NO;
    
//    WEAKSELF
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        
//        PPHomeAlumAddImageController *addimg = [[PPHomeAlumAddImageController alloc] init];
//        addimg.photos = photos;
//        [weakSelf.navigationController pushViewController:addimg animated:YES];
    PPAlbumEditContentViewController *createViewController = [[PPAlbumEditContentViewController alloc] init];
        
//        PPAlbumContentViewController *createViewController = [[UIStoryboard storyboardWithName:@"Album" bundle:nil] instantiateViewControllerWithIdentifier:@"PPAlbumContentViewController"];
//        createViewController.title = @"创建相册";
        createViewController.type = PPAlbumContentViewControllerTypeCreate;
        createViewController.images = photos;
        [self.navigationController pushViewController:createViewController animated:YES];
        
        
    }];
    
    [self presentViewController:imagePickerVc animated:NO completion:nil];
}


- (void)updatePramsparam:(NSDictionary *)dict{
    
    //更新电子书
    
    [PPNetworkService updateAlbumeBookWithParams:dict callback:^(id data, NSError *error) {
        
    }];
    
}



#pragma mark - 跳转电子书分享页面
- (void)listView:(PPHomeAlbumListView *)listView didSelectEbookAlbum:(PPAlbumModel *)album{

    [[PPNetworkManager sharedInstance] checkNetworkStatusChangeBlock:nil];
    if ([PPNetworkManager sharedInstance].networkStatus == PPNetStatusNotReachable) {
        [MBProgressHUD showError:@"请检查网络连接"];
        return;
    }
    
    PPHomeAlbumModel *albumModel = [self saveAlbumInfo:album];
    if (albumModel.pictures.count > 0) {
        for (PPPictureModel *pic in albumModel.pictures) {
            PPLog(@"打印%@",pic);
            if (pic.picKey.length <= 0) {
                [self.navigationController.view toastMessage:@"相册图片正在努力上传,请稍等"];
                return;
            }
        }
    }

    [MobClick event:@"17"];
    
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
    if (album.coverURLString) {
        [album queryAlbumCoverImageWithCompletion:^(UIImage *image,NSString *coverURL, NSError *error) {
            [hud hide:YES];
            PPLog(@"下载封面图");
            if(error == nil) {
                [self loadWithAlbum:album HUD:hud coverImg:image homeAlbumModel:albumModel];
            } else {
                PPLog(@"下载封面图失败 = %@",coverURL);
                [self.navigationController.view toastMessage:error.networkPrompt];
            }
        }];
    }else{
        PPPictureModel *p =  albumModel.pictures[0];
        NSString *coverURLString = [NSString stringWithFormat:@"%@%@",p.picHost,p.picKey];
        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:coverURLString] options:kNilOptions progress:nil completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
            
            if (error == nil) {
                [self loadWithAlbum:album HUD:hud coverImg:image homeAlbumModel:albumModel];
            }else{
                 [self.navigationController.view toastMessage:error.networkPrompt];
            }
            
        }];
        
    }
    

    
    
    
    
 
    
    

}

#pragma mark -加载电子书信息
- (void)loadWithAlbum:(PPAlbumModel *)album HUD:(MBProgressHUD *)hud coverImg:(UIImage *)coverImg homeAlbumModel:(PPHomeAlbumModel *)albumModel{
    
//    PPShareTemplateController *shareVc = [[PPShareTemplateController alloc] init];
////    shareVc.albumM = album;
//    shareVc.normalAlbumModel = albumModel;
//    shareVc.normalAlbumModel.coverImage = coverImg;



    albumModel.coverImage = coverImg;
    //查询是生成过电子书 (根据本地缓存模板文件)
//    NSMutableArray *templateArr =  [NSMutableArray arrayWithContentsOfFile:kTemplatePlist];
    NSMutableArray *templateArr = [NSKeyedUnarchiver unarchiveObjectWithFile:kTemplatePlist];
    
    if (templateArr.count <=0) {
//        未查到电子书
        dispatch_async(dispatch_get_main_queue(), ^{
            [hud hide:YES];
            PPShareTemplateController *shareVc = [[PPShareTemplateController alloc] init];
            shareVc.albumM = album;
            shareVc.normalAlbumModel = albumModel;
            [self.navigationController pushViewController:shareVc animated:NO];
        });
        return;
    }

    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    NSMutableDictionary *pageInfoDict = [NSMutableDictionary dictionary];
    [pageInfoDict setSafeObject:@(1) forKey:@"page"];
    [pageInfoDict setSafeObject:@(100) forKey:@"rows"];
    [dict setSafeObject:album.albumID forKey:@"albumId"];
    [dict setSafeObject:pageInfoDict forKey:@"pageInfo"];
    [dict setSafeObject:[album.order integerValue]==1?@"desc":@"asc" forKey:@"order"];
    
    [PPNetworkService gettemplateEbookListWithparams:dict callback:^(id data, NSError *error) {
        
        if (error==nil) {
            
                if ([data[@"total"] integerValue] == 0) {
                    PPLog(@"显示默认= %@",data);
                    PPShareTemplateController *shareVc = [[PPShareTemplateController alloc] init];
                    shareVc.albumM = album;
                    shareVc.normalAlbumModel = albumModel;
                    shareVc.normalAlbumModel.coverImage = coverImg;
                    //显示默认模板
                    [hud hide:YES];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [self.navigationController pushViewController:shareVc animated:NO];
                    });
                    
                }else{
                    //显示电子书模板
                    PPLog(@"显示电子书= %@",data);
                    if (!albumModel.ebookPictures) {
                        albumModel.ebookPictures = [NSMutableArray array];
                    }
                    
                    if (data[@"common"]) {
                        NSDictionary *commons = data[@"common"];
                        PPPictureModel *picCoverModel = [[PPPictureModel alloc] init];
                        picCoverModel.picID = commons[@"pictureId"];
                        //                    picCoverModel.picAuuid = obj.auuid;
                        picCoverModel.picKey = commons[@"url"];
                        picCoverModel.picHost = albumModel.coverHost;
                        picCoverModel.picDesc = commons[@"contentDescription"];
                        picCoverModel.picURL = [NSString stringWithFormat:@"%@%@",albumModel.coverHost,commons[@"url"]];
                        picCoverModel.eBookTemplateId = commons[@"eBookTemplateId"];
                        picCoverModel.picInTemplateId = commons[@"picInTemplateId"];
                        picCoverModel.picType = 1;
//                        if (albumModel.ebookPictures.count >0) {
                            [albumModel.ebookPictures insertObject:picCoverModel atIndex:0];
//                        }else{
//                            [albumModel.ebookPictures addObject:picCoverModel];
//                        }
                        
                        
                    }
                    
                    if (data[@"rows"]) {
                        NSArray *rows = data[@"rows"];
                        for (NSDictionary *rowDict in rows) {
                            PPPictureModel *picImgModel = [[PPPictureModel alloc] init];
                            picImgModel.picID = rowDict[@"pictureId"];
                            //                    picCoverModel.picAuuid = obj.auuid;
                            picImgModel.picKey = rowDict[@"url"];
                            picImgModel.picHost = albumModel.coverHost;
                            picImgModel.picDesc = rowDict[@"contentDescription"];
                            picImgModel.picURL = [NSString stringWithFormat:@"%@%@",albumModel.coverHost,rowDict[@"url"]];
                            picImgModel.eBookTemplateId = rowDict[@"eBookTemplateId"];
                            picImgModel.picInTemplateId = rowDict[@"picInTemplateId"];
                            picImgModel.picType = 2;
                            
                            if (albumModel.order == 1 && albumModel.ebookPictures.count>1) {
                                
                                [albumModel.ebookPictures insertObject:picImgModel atIndex:1];
                            }else{
                                [albumModel.ebookPictures addObject:picImgModel];
                            }
                        
                        }
                        
                    }
                    PPPictureModel *tempM = [albumModel.ebookPictures firstObject];
                    PPTemplateModel *templateModel;
                    BOOL isEbook = FALSE;
                    if (templateArr.count > 0) {
                        //查询到了电子相册 且本地有模板数据 才会显示电子相册 否则显示默认模板
                        for (int i = 0; i<templateArr.count; i++) {
                            PPTemplateModel *temp;
                            if ([templateArr[i] isKindOfClass:[PPTemplateModel class]]) {
                                temp = (PPTemplateModel *)templateArr[i];
                            }else{
                                temp = [PPTemplateModel yy_modelWithDictionary:templateArr[i]];
                            }
                            if ([temp.eBookTemplateId isEqualToString:tempM.eBookTemplateId]) {
                                //本地有模板数据
                                for (id ebookAlbumDict  in temp.albums) {
                                    PPEbookAlbum *ebookA;
                                    if ([ebookAlbumDict isKindOfClass:[PPEbookAlbum class]]) {
                                        ebookA = (PPEbookAlbum*)ebookAlbumDict;
                                    }else{
                                        ebookA = [PPEbookAlbum yy_modelWithDictionary:ebookAlbumDict];
                                    }
                                    
                                    if (ebookA.albumID == album.albumID) {
                                        templateModel = temp;
                                        isEbook = TRUE;
                                        ebookA.downloadType = PPTemplateDownLoadTypeEmploy;
                                    [templateArr replaceObjectAtIndex:i withObject:temp];
                                    }
                                }
                                
                            }
                        }
                        if (isEbook) {
//                            [templateArr writeToFile:kTemplatePlist atomically:YES];
                            [NSKeyedArchiver archiveRootObject:templateArr toFile:kTemplatePlist];
                            //
                        }
                    }

                    if (tempM.picType == 1 && tempM.picURL) {
                        [PPNetworkManager downLoadImageWithUrl:tempM.picURL callback:^(UIImage *downImage, NSError *error) {
                            [hud hide:YES];
                            if (error == nil) {
//                                tempM.coverImage = downImage;
                                PPShareTemplateController *shareVc = [[PPShareTemplateController alloc] init];
                                shareVc.albumM = album;
                                albumModel.eBookCoverImage = downImage;
                                shareVc.normalAlbumModel = albumModel;
                                if (isEbook) {
                                    shareVc.albumM = album;
                                    shareVc.eBookTemplateModel = templateModel;
                                    dispatch_async(dispatch_get_main_queue(), ^{
                                        
                                        [self.navigationController pushViewController:shareVc animated:NO];
                                    });
                                }else{
                                //本地模板获取失败
                                    PPShareTemplateController *shareVc = [[PPShareTemplateController alloc] init];
                                    [albumModel.ebookPictures removeAllObjects];
                                    shareVc.albumM = album;
                                    shareVc.normalAlbumModel = albumModel;
                                    dispatch_async(dispatch_get_main_queue(), ^{
                                        [self.navigationController pushViewController:shareVc animated:NO];
                                    });
                                    
                                }
                                
                            }else{
                                [self.navigationController.view toastMessage:error.networkPrompt];
                            }
                        }];
                    }else{
                        //电子书封面没有
                        PPShareTemplateController *shareVc = [[PPShareTemplateController alloc] init];
                        shareVc.normalAlbumModel = albumModel;
                        shareVc.albumM = album;
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [self.navigationController pushViewController:shareVc animated:NO];
                        });
                    }

                }
            }else{
                [hud hide:YES];
                [self.navigationController.view toastMessage:error.networkPrompt];
                
            }
    
    }];  
}

#pragma mark -获取默认相册的信息
- (PPHomeAlbumModel *)saveAlbumInfo:(PPAlbumModel *)album{
    
    PPHomeAlbumModel *albumModel = [[PPHomeAlbumModel alloc] init];
    albumModel.auuid = album.auuid;
    albumModel.albumID = album.albumID;
    albumModel.coverURL = [NSString stringWithFormat:@"%@%@",album.coverHost,album.coverKey];
    albumModel.coverHost = album.coverHost;
    albumModel.coverKey = album.coverKey;
    albumModel.order = [album.order integerValue];
    albumModel.title = album.title;
    albumModel.albumDesc = album.desc;
    albumModel.permission = album.permission;
    albumModel.publish = album.publish;
    albumModel.update = album.update;
    albumModel.privacy = album.privacy;
    albumModel.title2 = album.desc;
    albumModel.privacyUserIDs = album.privacyUserIDs;
    
    NSArray <PPAlbumImageModel *> *images = [PPAlbumImageModel where:@{@"auuid" : album.auuid, @"deleted" : @(NO)}];
    NSArray *sortedImages = nil;
    if(album.order.integerValue == PPAlbumOrderDesc) {
        sortedImages = images;
    } else {
        sortedImages = [images.reverseObjectEnumerator allObjects];
    }
    
    albumModel.pictures = [NSMutableArray array];
    
    //添加内页
    [sortedImages enumerateObjectsUsingBlock:^(PPAlbumImageModel *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
        PPPictureModel *picModel = [[PPPictureModel alloc] init];
        picModel.picID = obj.imageID;
        picModel.picAuuid = obj.auuid;
        picModel.picKey = obj.key;
        picModel.picHost = obj.host;
        picModel.picDesc = obj.desc;
        picModel.picComment = obj.comment;
        picModel.picLike = obj.like;
        picModel.picURL = [NSString stringWithFormat:@"%@%@",obj.host,obj.key];
        picModel.picType = 2;
        [albumModel.pictures addObject:picModel];
        
        if ([obj.key isEqualToString:albumModel.coverKey]) {
            PPPictureModel *picCoverModel = [[PPPictureModel alloc] init];
            picCoverModel.picID = obj.imageID;
            picCoverModel.picAuuid = obj.auuid;
            picCoverModel.picKey = obj.key;
            picCoverModel.picHost = obj.host;
            picCoverModel.picDesc = obj.desc;
            picCoverModel.picComment = obj.comment;
            picCoverModel.picLike = obj.like;
            picCoverModel.picURL = [NSString stringWithFormat:@"%@%@",obj.host,obj.key];
            picCoverModel.picType = 1;
            [albumModel.pictures insertObject:picCoverModel atIndex:0];
        }
    }];
    
    return albumModel;
}
@end
